﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using TravelAgencySilverlight.Web;
using TravelAgencySilverlight.Web.Services;

namespace TravelAgencySilverlight.Models
{
    public static class TravelAgencyModel
    {
        public static void TryGetPhotosAsync(Action<Exception, IEnumerable<Photo>> completed)
        {
            TravelAgencyDomainContext service = new TravelAgencyDomainContext();

            var query = service.GetPhotosQuery();
            var loadOp = service.Load(query);

            loadOp.Completed += (s, args) =>
            {
                if (loadOp.HasError)
                {
                    loadOp.MarkErrorAsHandled();
                    completed(loadOp.Error, null);                    
                }
                else
                {
                    completed(null, service.Photos);                    
                }
            };
        }

        //public static void TryGetTripsAsync(Action<bool, IEnumerable<Photo>> completed)
        //{
        //    TravelAgencyDALServiceClient service = new TravelAgencyDALServiceClient();

        //    service.GetPhotosCompleted += (s, args) =>
        //    {
        //        if (args.Error == null)
        //        {
        //            completed(true, args.Result);
        //        }
        //        else
        //        {
        //            completed(false, null);
        //        }
        //    };

        //    service.GetPhotosAsync();
        //}
    }
}
